<%@page import="java.net.URL"%>
<%@page import="java.util.Date"%>
<%@page import="java.io.InputStreamReader"%>
<%@page import="java.util.LinkedList"%>
<%@page import="java.io.FileReader"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.text.DateFormat"%>
<%@page import="java.io.File"%>
<%@page import="java.io.BufferedReader"%>
<%!
BufferedReader reader=null;
File file;
LinkedList<String> ll=new LinkedList<String>();
URL url;
%>

<%
                String com=request.getParameter("com");
                Date dt=new Date(System.currentTimeMillis());
                int day=dt.getDate();
                int month=dt.getMonth()+1;
                int year=dt.getYear()+1900;
//out.print(year);
String u="http://ichart.yahoo.com/table.csv?s="+com+"&d="+(month-1)+"&e="+(day)+"&f="+year+"&a="+(month-1)+"&b="+(day)+"&c="+(year-1)+"&g=d&ignore=.csv";

URL url=new URL(u);
      reader = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"));
                //File f = new File("D:/project/web/sensex.csv");
                //reader = new BufferedReader(new FileReader(f));
               
              // url = new URL("http://ichart.yahoo.com/table.csv?s=AAPL&d=0&e=31&f=2010&a=0&b=1&c=2009&g=d&ignore=.csv");
              
  //        
                String s1,a=null,b=null,c=null,d=null,e=null;
                int k=0,j;
                Long l;
                Date dt1=null;
                
               DateFormat df;
               df=new SimpleDateFormat("yyyy-MM-dd");
               
               
               while((s1=reader.readLine())!=null){
                    
                             if(k==0){
                                 k++;
                                 continue;
                            }   
                             
                                 
                             
                        String[] tokens = s1.split(",");
                        
                        for(int i=0;i<tokens.length;i++)
                        {
                            if(i==0){
                                dt1=(Date)df.parse(tokens[i]);
                                l=dt1.getTime();
                                a="[";
                                a= a.concat(l.toString());
                            }
                            
                            if(i==5)
                                b=tokens[i];
                           /* if(i==2)
                                c=tokens[i];
                            if(i==3)
                                d=tokens[i];
                            if(i==4)
                                e=tokens[i];
                            
                             */                             
                            }
                       
                            a=a.concat(","+b+"]");
                           // out.print(a);
                            ll.push(a);                   
                            k++;
                        }
                   
                    
                    out.print(ll.toString());
                    reader.close();

%>